#!/usr/bin/env ruby
#
# Copyright 2009, Jeffrey Palm.
#

require 'socket'
require 'config'
require 'util'

#
# Starts up a simple TCP client and reads from the user what to send
# the server.  The arguments are defined in config.rb.
#
def main(args)
  c = Config.get_instance args

  note 'Starting up the client'
  note 'Host: ' + c.addr
  note 'Port: ' + c.port.to_s

  loop do

    # Get the input from the user
    print 'Enter some text or \'quit\' to quit: ' 
    str = gets
    if str.downcase == 'quit'
      note 'And we\'re done.'
      break
    end

    # Send it to the server
    note 'Sending: ' + str
    begin
      s = TCPSocket.open c.addr,c.port
      s.puts str
      s.close
    rescue Exception => e
      break
    end
  end
end

main ARGV

